/**
 * Module dependencies.
 */

var express = require('./controller/node_modules/express')
    , routes = require('./controller/routes')
    , user = require('./controller/routes/user')
    , http = require('http')
    , path = require('path')
//, MongoStore = require('connect-mongo')(express)
    , settings = require('./settings')
    , flash = require('./controller/node_modules/connect-flash');
//    , dbstart = require('./models/dbrun');
/*
 ls.stdout.on('data', function (data) {
 console.log('stdout: ' + data);
 });

 ls.stderr.on('data', function (data) {
 console.log('stderr: ' + data);
 });

 ls.on('close', function (code) {
 console.log('child process exited with code ' + code);
 });
 */
var app = express();
// all environments
app.set('port', process.env.PORT || 3001);
app.set('views', __dirname + '/views/ejs');
app.set('view engine', 'ejs');
app.use(flash());
//app.use(express.favicon());
app.use(express.favicon(__dirname + '/favicon.ico'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(app.router);
app.use(express.static(path.join(__dirname, '')));
//dbstart.run(function(){
//    app.use(express.session({
//        secret: settings.cookieSecret,
//        key: settings.db,
//        cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
//        store: new MongoStore({
//            db: settings.db
//        })
//    }));
//});
// development only
if ('development' == app.get('env')) {
    app.use(express.errorHandler());
}
app.get('/', routes.index);
app.get('/users', user.list);
app.all('*', function (req, res, next) {
    var isIE = req.header("user-agent").search('MSIE') > -1;
    console.log('isIE:' + isIE);
    if (!isIE) {
        next();
    } else {
        res.send("Sorry,I can't support IE!");
    }
});
http.createServer(app).listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));

});
